#if defined(_MSC_VER)
#pragma once
#endif

#ifndef LM_CORE_INTERSECTION_H
#define LM_CORE_INTERSECTION_H

#include "lm.h"
#include "geometry.h"
#include "frame.h"
#include "transform.h"
#include "spectrum.h"

struct Intersection {
public:
	inline Intersection() : t(INFINITY), shape(NULL), hasUVPartials(false), le(0.f), isLight(false) {
		b0 = b1 = b2 = 0.f;
	}

	inline Vector3 ToWorld(const Vector3 &v) const {
		return shadingFrame.ToWorld(v);
	}
	inline Vector3 ToLocal(const Vector3 &v) const {
		return shadingFrame.ToLocal(v);
	}
	inline bool IsValid() const {
		return t != INFINITY;
	}
	// Note : TO DO!!
	BSDF *GetBSDF(const RayDifferential &ray);
	// Note : TO DO!!
	// Check whether the intersection in a area light
	inline bool IsLight() const {
		return isLight;
	}
	// Note : TO DO!!
	// Check whether we need a subsurface integrator
	inline bool HasSubsurface() const;

	// Does the surface mark a transition bt two media
	//inline bool idMediumTransition() const;
	// Note : TO DO!!
	inline Spectrum Le(const Vector3 &d) const {
		return le;
	}

	// Compute texture coordinate partials
	void ComputePartials(const RayDifferential &ray) const;

	std::string ToString() const;
	// Public Data
	// distance for intersection
	float t;
	// Intersection point
	Point3 p;
	// geometry frame
	Frame geometryFrame;	//s,t,n	s = dpdu t = dpdv n = nn
	// shading frame
	mutable Frame shadingFrame;		//s,t,n
	// UV surface coordinates
	Point2 uv;
	// Transform from  world space to object space 
	const Transform *worldToObject;
	const Transform *objectToWorld;
	// Position partials wrt. the texture space parameterization
	Vector3 dpdu, dpdv;
	// 
	mutable Normal dndu, dndv;
	// Texture coordinate mapping partials wrt. changes in screen-space
	mutable float dudx, dudy, dvdx, dvdy;
	// time value associated with the intersection
	float time;
	// Incident direction in the local frame
	//Vector3 wi;
	// Affected shape
	const Shape *shape;
	// Has texture coordinate partials been computed
	mutable bool hasUVPartials;
	// Spectrum
	Spectrum le;
	bool isLight;
	// barycentric coordinate for triangle
	float b0, b1, b2;
};

#endif	// LM_CORE_INTERSECTION_H